<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pembayaran_sekali_masal extends CI_Controller {
	function __construct() {
        parent::__construct();
        $this->isLogin();	
		$this->load->model("master/master_set_sekali"); 
		$this->load->model("master/master_tapel"); 	
		$this->load->model("master/master_siswa"); 
		$this->load->model("pembayaran_sekali_model"); 
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function index(){
		$data['main_view']='pembayaran_sekali_masal/hasil';
		//$id_lembaga=$this->session->userdata('id_lembaga');
		$data['aksi_simpan']='pembayaran_sekali_masal/simpan';
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$hasil=$this->pembayaran_sekali_model->get_tagihan_siswa_belum_set();
		foreach($hasil as $key=>$val){
			$hasil[$key]['list_tagihan']=$this->master_set_sekali->get_detail($val['id_tapel_masuk'],$val['id_lembaga']);
		}
		$data['hasil']=$hasil;
		//echo "<pre>";
		//print_r($hasil);exit;
		$this->load->view('index',$data);
	}
	
	function simpan(){
		$nis=$this->input->post('nis');
		$id_lembaga=$this->input->post('id_lembaga');
		$tapel=$this->input->post('tapel');
		$status_simpan=$this->input->post('status_simpan');
		//$id_lembaga=$this->session->userdata('id_lembaga');
		if(!empty($nis)){
			foreach($nis as $key=>$val){
				if($status_simpan[$key]=="ya"){
					//simpan
					$list_tagihan=$this->master_set_sekali->get_detail($tapel[$key],$id_lembaga[$key]);
					//print_r($list_tagihan);
					//simpan tagihan
					if(!empty($list_tagihan)){
						foreach($list_tagihan as $val_tagihan){
							$insert=$this->pembayaran_sekali_model->insert_tagihan($tapel[$key],$val_tagihan['id_komponen'],$val_tagihan['nominal'],$nis[$key]);
						}
					}
				}
			}
		}
		//exit;
		$this->session->set_flashdata('pesan', 'Setting Pembayaran Siswa Masal Sukses Diinput');
		redirect('pembayaran_sekali_masal');
	}
}

?>